<?php

class cDAO {
	var $con;
	
	function __construct($connection){
		$this->con = $connection;
	}
	
	function query($sql){
		
		if (_DEBUG == true)
			echo $sql;
		return mysql_query($sql,$this->con);
	}
	
	function getInsertId(){
		return mysql_insert_id();
	}
		
	function affected_rows(){
		return mysql_affected_rows($this->con);
	}
	
	function getNumRows($r){
		return mysql_num_rows($r);
	}
	
	// query 반환 - var, 단일값
	public function getCell($sql){
		$result = mysql_fetch_row($this->query($sql));
        return $result[0];
	}
	// query 반환 - array[col], 1차원배열, 단수행
	public function getRow($sql){
		return mysql_fetch_assoc($this->query($sql));
	}

	// query 반환 - array[row][col], 2차원배열, 복수행
	public function getSheet($sql){
		$result = $this->query($sql);
        if($result === false) return false;
        $this->selected_rows_num = mysql_num_rows($result);
        // 레코드가 없으면 빈 배열 반환
        if($this->selected_rows_num == 0) return null;
        // 있으면, 배열로 반환
        while ($row = mysql_fetch_assoc($result)) { $sheet[] = $row; }
        mysql_free_result($result);
        return $sheet;
	}
	
	function getTotalRecoed($name){
		$resultQuery = $this->query("select num from bt_totalRecord where name='$name'");
		$rst = mysql_fetch_row($resultQuery);
		return $rst[0];		
	}
}
?>